<?php
namespace app\index\controller;
use app\common\controller\Frontend;
use think\Validate;
use app\common\model\Account;
use think\Session;
class Login extends Frontend{

    public function index()
    {
        
        if($this->request->isPost()){
            $data = $this->request->post('',[],'strip_tags');
            $rule = [
                'account'  => 'require',
                'secret'  => 'require',
            ];
            $validate = new Validate($rule, [], ['username' => '账户', 'password' => '密码']);
            $result = $validate->check($data);
            if (!$result) {
                $this->error($validate->getError());
            }
            $result = Account::where('account', $data['account'])->where('secret', $data['secret'])->find();
            if (!empty($result)) {
                
                Session::set('ACCOUNT', $result,'svip');
                $this->success('登录成功');
            } else {
                $msg =  '账户或者密码错误';
                $this->error($msg);
            }
        }
        if (Session::has('ACCOUNT','svip')) {
            Session::delete("referer");
            $this->redirect('index/index');
        }
        return $this->fetch();
    }

}
?>